package com.videoplayer;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.db.DBConnect;
import com.umeng.analytics.MobclickAgent;

public class SettingSharpnessActivity extends Activity implements
		OnClickListener {
	private final String COLUME_SHARPNESS = "sharpness";
	private RelativeLayout rlSharpnessLow;
	private RelativeLayout rlSharpnessHigh;
	private RelativeLayout rlSharpnessSuper;
	private int intentValue;
	private ImageView ivLow;
	private ImageView ivHigh;
	private ImageView ivSuper;
	private DBConnect dbCon;
	private Button btnBack;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		MobclickAgent.onError(this);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.sharpness_activity);
		intentValue = getIntent().getExtras().getInt("sharpness");
		rlSharpnessLow = (RelativeLayout) findViewById(R.id.rl_sharpness_low);
		rlSharpnessHigh = (RelativeLayout) findViewById(R.id.rl_sharpness_high);
		rlSharpnessSuper = (RelativeLayout) findViewById(R.id.rl_sharpness_super);
		rlSharpnessLow.setOnClickListener(this);
		rlSharpnessHigh.setOnClickListener(this);
		rlSharpnessSuper.setOnClickListener(this);
		ivLow = (ImageView) findViewById(R.id.iv_sharpness_low);
		ivHigh = (ImageView) findViewById(R.id.iv_sharpness_high);
		ivSuper = (ImageView) findViewById(R.id.iv_sharpness_super);
		btnBack = (Button)findViewById(R.id.btn_setting_sharpness_back);
		btnBack.setOnClickListener(this);
		dbCon = new DBConnect(this);
		switch (intentValue) {
		case 0:
			lowChecked();
			break;
		case 1:
			highChecked();
			break;
		case 2:
			superChecked();
			break;

		default:
			break;
		}
	}

	private void lowChecked() {
		ivLow.setBackgroundResource(R.drawable.status_enable);
		ivHigh.setBackgroundResource(R.drawable.status_disable);
		ivSuper.setBackgroundResource(R.drawable.status_disable);
		intentValue = 0;
	}

	private void highChecked() {
		ivLow.setBackgroundResource(R.drawable.status_disable);
		ivHigh.setBackgroundResource(R.drawable.status_enable);
		ivSuper.setBackgroundResource(R.drawable.status_disable);
		intentValue = 1;
	}

	private void superChecked() {
		ivLow.setBackgroundResource(R.drawable.status_disable);
		ivHigh.setBackgroundResource(R.drawable.status_disable);
		ivSuper.setBackgroundResource(R.drawable.status_enable);
		intentValue = 2;
	}
	
	private long setDBValue(String name,int value){
		dbCon.open();
		long result = dbCon.updateValue(name, value);
		dbCon.close();
		return result;
	}
	

	@Override
	protected void onResume() {
		super.onResume();
		MobclickAgent.onResume(this);
	}

	@Override
	protected void onPause() {
		super.onPause();
		MobclickAgent.onPause(this);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.rl_sharpness_low:
			lowChecked();
			setDBValue(COLUME_SHARPNESS,intentValue);
			break;
		case R.id.rl_sharpness_high:
			highChecked();
			setDBValue(COLUME_SHARPNESS,intentValue);
			break;
		case R.id.rl_sharpness_super:
			superChecked();
			setDBValue(COLUME_SHARPNESS,intentValue);
			break;
		case R.id.btn_setting_sharpness_back:
			this.finish();
			break;
		default:
			break;
		}
	}
}
